package com.app.micaihu.view.main.dialog

import android.content.DialogInterface
import android.content.Intent
import com.app.base.BaseDialogFragment
import com.app.micaihu.R
import com.app.micaihu.configure.Config
import com.app.micaihu.configure.ConfigKeyConstant
import com.app.micaihu.manager.AppConfigManager
import com.app.micaihu.manager.UserInforManager
import com.app.micaihu.view.login.activity.QuickLoginActivity
import com.app.micaihu.view.user.userinfo.activity.WebActivity
import com.blankj.utilcode.util.SPUtils
import kotlinx.android.synthetic.main.dialog_agree.*

class MainAgreeDialogFragment : BaseDialogFragment() {
    companion object {
        @JvmStatic
        fun newInstance(): MainAgreeDialogFragment = MainAgreeDialogFragment()
    }

    override fun getLayoutId(): Int {
        return R.layout.dialog_agree
    }

    override fun setData() {
    }

    override fun addListeners() {
        tvUserProtocol.setOnClickListener {    //用户协议
            val userAgreementUrl = AppConfigManager.getInstance().configSP.getString(ConfigKeyConstant.userAgreementUrl, "")
            val intent = Intent(context, WebActivity::class.java)
            intent.putExtra(Config.Extra.url, userAgreementUrl)
            startActivity(intent)
        }
        tvPrivacyProtocol.setOnClickListener { //隐私协议
            val privateAgreementUrl = AppConfigManager.getInstance().configSP.getString(ConfigKeyConstant.privateAgreementUrl, "")
            val intent = Intent(context, WebActivity::class.java)
            intent.putExtra(Config.Extra.url, privateAgreementUrl)
            startActivity(intent)
        }
        btnAgree.setOnClickListener {
            this.dismiss()
            SPUtils.getInstance().put(ConfigKeyConstant.isFirstShowAgreement, false)
            val mIntentLogin = Intent(activity, QuickLoginActivity::class.java)
            startActivityForResult(mIntentLogin, UserInforManager.TO_LOGIN_REQUESTCODE)
            activity?.overridePendingTransition(R.anim.translate_slide_in_bottom, R.anim.slide_out_left)
        }
    }

    override fun canceledOnTouchOutside(): Boolean {
        return false
    }

    override fun cancelable(): Boolean {
        return false
    }

    override fun onDismiss(dialog: DialogInterface) {
        super.onDismiss(dialog)
    }
}